require "forwardable"
require "active_support/core_ext/string/starts_ends_with"
require "active_support/core_ext/string/inquiry"

class Symbol
  extend Forwardable

  def_delegators :to_s, :inquiry, :ends_with?

  # @!method inquiry()
  #   Allows for any symbol to be "inquired" with a call ending with a `?`
  #
  #   @return [true] if the method name matches the Symbol
  #   @return [false] otherwise
  #   @example
  #     :foo.foo? => true
  #     :foo.bar? => false
  #   @example Error
  #     :foo.foo => raises NoMethodError
  #   @see http://api.rubyonrails.org/v3.2.5/classes/String.html#method-i-inquiry
  #        String#inquiry in ActiveSupport    

  # @!method ends_with?(str)
  #   Check that the Symbol ends with the given String
  #
  #   @param str [String] string to check for
  #   @return [true] if the Symbol ends with the given String
  #   @return [false] otherwise
  #   @see http://api.rubyonrails.org/v3.2.5 String#ends_with? in ActiveSupport

  private

  # Passes method names ending with `?` through to `#to_s.inquiry`
  def method_missing(method_name, *arguments, &block)
    if arguments.empty? and block.nil? and method_name.ends_with?("?")
      self.inquiry.send(method_name)
    else
      super
    end
  end
end
